package com.lbs.tdrive.adapter;

import java.util.List;
import java.util.zip.Inflater;

import com.lbs.tdrive.R;
import com.lbs.tdrive.data.Vehicle;
import com.lbs.tdrive.travel.AlertActivity;
import com.lbs.tdrive.travel.VehicleActivity;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class VehicleAdapter extends BaseAdapter {
	private List<Vehicle> vehicleList;
	private Context cntxt;
private  Handler handler;
	
	public VehicleAdapter(Context ctx,Handler handler, List<Vehicle> vehicleList) {
		this.cntxt= ctx;
		this.handler=handler;
		this.vehicleList=vehicleList;
	}


	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return (vehicleList.size());
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v=null; 
		if(convertView==null) {
		LayoutInflater inflater = LayoutInflater.from(cntxt);
		 v = inflater.inflate(R.layout.vehicle_item, null);
		} else {
			v=convertView;
		}
		TextView tv =  (TextView) v.findViewById(R.id.vehicletext);
		ImageView iv=(ImageView)v.findViewById(R.id.deletevehicle);
		final int pos=position;
		iv.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Message msg=new Message();
				msg.what=VehicleActivity.DELETE_VEHICLE;
				msg.arg1=pos;
				handler.sendMessage(msg);
				
			}
		});
		tv.setText(vehicleList.get(position).getVehicleName());
		return v;
		// TODO Auto-generated method stub
		
	}

}
